package pl.grabar.clinic.client.web.actions.reception.visit;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import pl.grabar.clinic.core.dao.Dao;
import pl.grabar.clinic.core.domain.person.Doctor;
import pl.grabar.clinic.core.domain.person.User;
import pl.grabar.clinic.core.domain.visit.Visit;
import pl.grabar.clinic.core.domain.visit.VisitSchedule;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@Action("new")
@InterceptorRef("grabarStack")
@Results({ @Result(name = "success", location = "edit.jsp"), @Result(name = "input",  type = "redirectAction", location = "list") })
public class NewVisitAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -5935693556755787047L;

	private static final Log LOG = LogFactory.getLog(NewVisitAction.class);

	@Autowired
	private Dao<Visit> visitDao;
	
	@Autowired
	private Dao<VisitSchedule> visitScheduleDao;
	
	@Autowired
	private Dao<Doctor> doctorDao;

	private Visit visit;
	
	private VisitSchedule visitSchedule;
	
	private Map<Long, String> doctors = new HashMap<>();
	
	@Override
	public void prepare() throws Exception {
		visit = new Visit();
		visitSchedule = new VisitSchedule();
		
		for (Doctor doctor : doctorDao.findAll()) {
			doctors.put(doctor.getId(), doctor.getFullName()+ " - " + doctor.getSpecialization());
			
		}
		System.out.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(doctors));
	}

	@Override
	public void validate() {
	}

	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}

	/*QKCESORY*/
	
	public Visit getVisit() {
		return visit;
	}

	public void setVisit(Visit visit) {
		this.visit = visit;
	}

	public void setVisitDao(Dao<Visit> visitDao) {
		this.visitDao = visitDao;
	}

	public VisitSchedule getVisitSchedule() {
		return visitSchedule;
	}

	public void setVisitSchedule(VisitSchedule visitSchedule) {
		this.visitSchedule = visitSchedule;
	}

	public void setVisitScheduleDao(Dao<VisitSchedule> visitScheduleDao) {
		this.visitScheduleDao = visitScheduleDao;
	}

	public Map<Long, String> getDoctors() {
		return doctors;
	}

	public void setDoctors(Map<Long, String> doctors) {
		this.doctors = doctors;
	}

	public void setDoctorDao(Dao<Doctor> doctorDao) {
		this.doctorDao = doctorDao;
	}



	
}